package ru.aslanov.schedule.client.ds;

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.types.FieldType;
import ru.aslanov.schedule.client.ScheduleUser;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * Created: Feb 2, 2010 3:49:21 PM
 *
 * @author Sergey Aslanov
 */
public class DancesDS extends ChildDS {
    //private static DancesDS instance = null;
    private static Map<String, DataSource> instances = new HashMap<String, DataSource>();

    public static DataSource getInstance(ScheduleUser scheduleUser) {
        DataSource dataSource = instances.get(scheduleUser.getScheduleKey());
        if (dataSource == null) {
            dataSource = new DancesDS(scheduleUser.getScheduleKey(), scheduleUser);
            instances.put(scheduleUser.getScheduleKey(), dataSource);
        }
        return dataSource;
    }


    private DancesDS(String scheduleKey, InputLangProvider inputLangProvider) {
        super("Dance", scheduleKey, "schedule", inputLangProvider);

        DataSourceField idField = new DataSourceField("id", FieldType.TEXT, cnt.idField(), 20);
        //idField.setRequired(true);
        idField.setHidden(true);

        DataSourceField name = new DataSourceField("name", FieldType.TEXT, cnt.nameField(), 40);
        name.setRequired(true);

        DataSourceField url = new DataSourceField("url", FieldType.LINK, cnt.urlField(), 100);

        setFields(encodedKey, /*scheduleKey, */idField, name, url);
    }
}
